"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Small = void 0;
const Utils_1 = __importDefault(require("./Utils"));
class Small {
    constructor(gameMgr, player, point) {
        this.level = 1;
        this.is_ready = false;
        this.action = 0; //行动力
        this.power = 0; //科技点
        this.gameMgr = gameMgr;
        this.player = player;
        this.point = point;
        this.point.small = this;
    }
    toObj() {
        let obj = {
            "point_id": this.point.id,
            "is_ready": this.is_ready,
            "action": this.action,
            "power": this.power,
            "level": this.level
        };
        return obj;
    }
    /** 通知客户端刷新数据 */
    update() {
        clearTimeout(this.updateTimeout);
        this.updateTimeout = setTimeout(() => {
            if (this.gameMgr != null) {
                this.gameMgr.sendBroadcast(Utils_1.default.getObj("update_small", { "small": this.toObj() }, true, false), false);
            }
        }, 20);
    }
    die(murderer) {
        this.gameMgr.sendBroadcast(Utils_1.default.getObj("small_die", { "point_id": this.point.id }));
        if (this.player != murderer) {
            murderer.small.changePower(5);
            this.gameMgr.handlerMgr.showToast(murderer, "击杀小子，获得5点科技点");
        }
        this.point.small = null;
        this.player.is_death = true;
        this.player.arr_bigs.forEach(big => {
            big.die(murderer);
        });
        this.gameMgr.switchTurnPlayer(this.player);
        this.gameMgr.checkAlive();
    }
    turnOver() {
        this.is_ready = false;
        this.action = 0;
        this.update();
    }
    turnStart() {
        this.is_ready = true;
        this.action += 6;
        this.update();
    }
    changeAction(num) {
        this.action += num;
        this.update();
    }
    changePower(num) {
        this.power += num;
        this.update();
    }
}
exports.Small = Small;
